using System;
using System.Collections.Generic;
using System.Text;
using ENTITIES;
using DAL;
using Utility;

namespace BUS
{
   public class KhachHangBUS
    {
       
        public static void Insert(TBKhachHang kh)
        {
            KhachHangDAL khDAL = new KhachHangDAL();
            khDAL.Insert(kh);
        }
        public static void Update(TBKhachHang kh)
        {
            KhachHangDAL khDAL = new KhachHangDAL();
            khDAL.Update(kh);
        }
        public static void Delete(int iD)
        {
            KhachHangDAL khDAL = new KhachHangDAL();
            khDAL.Delete(iD);
        }
        public static tbKhachHangCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            KhachHangDAL khDAL = new KhachHangDAL();
            return khDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbKhachHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            KhachHangDAL khDAL = new KhachHangDAL();
            return khDAL.Get(cri.Criter, 0, 0, tbKhachHangColumns.MaKH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static TBKhachHang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachHangColumns.MaKH.ToString(), Condition.EQUAL, iD);
            KhachHangDAL khDAL = new KhachHangDAL();
            tbKhachHangCollection khachhangcollection = khDAL.Get(cri.Criter,
                  0, 0, tbKhachHangColumns.MaKH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (khachhangcollection.Count > 0)
                return khachhangcollection[0];
            return null;
        }
        public static tbKhachHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            KhachHangDAL khDAL = new KhachHangDAL();
            return khDAL.Get(cri.Criter, 1, number,
             tbKhachHangColumns.MaKH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbKhachHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            KhachHangDAL khDAL = new KhachHangDAL();
            return khDAL.Get(cri.Criter, 1, number,
               tbKhachHangColumns.MaKH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    }

